package io.linfeng.api.app.webSocket.controller;

import io.linfeng.common.annotation.Login;
import io.linfeng.common.api.R;
import io.linfeng.service.im.entity.SocketMsg;
import io.linfeng.service.im.server.WebSocketService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author RJF
 * @date create at 2024-05-2024/5/7-19:20
 * copyright @2024 China Automotive Technology & Research Center Co.Ltd
 */
@RestController
@RequestMapping("/app/socket")
@Api(tags = "聊天api")
public class WebSocketController {

    @Resource
    private WebSocketService service;
    /**
     * 向指定用户发送消息
     */
    @Login
    @PostMapping("/send/messageToUsername")
    @ApiOperation("给指定用户发送消息")
    public R privateMessage(@RequestBody SocketMsg socketMsg) {
        if (service.privateMessage(socketMsg)) {
            return R.ok();
        } else {
            return R.error("消息发送失败！");
        }

    }

    /**
     * 向群聊用户发送消息
     */
    @Login
    @PostMapping("/send/message")
    @ApiOperation("给群聊发送消息")
    public void publicMessage(String userName, String message, boolean flag) {
        service.publicMessage(userName,message,flag);
    }
}
